import Vue from 'vue'
import VueRouter from 'vue-router'
import RegiSter from '../views/RegiSter/RegiSter.vue'
import store from '@/store'
Vue.use(VueRouter)

const routes = [{
    path: "/",
    redirect: "/RegiSter"
  },
  {
    path: "/RegiSter",
    name: "RegiSter",
    component: RegiSter,
    meta: {
      // 设置自定义属性
      isShow: false,
    }
  },
  {
    path: '/NaviGation',
    name: 'NaviGation',
    component: () => import('../views/NaviGation/NaviGation.vue'),
    children: [{
        path: "/",
        redirect: "/NaviGation/HomePage"
      },
      {
        path: "/NaviGation/HomePage",
        name: "HomePage",
        component: () => import('../views/HomePage/HomePage.vue'),
        meta: {
          isShow: true,
          title: "首页"
        }
      },
      {
        path: "/NaviGation/TackView",
        name: "TackView",
        component: () => import('../views/HomePage/comment/TackView.vue'),
        meta: {
          isShow: true,
          title: "系统设置"
        }
      },
      {
        path: "/NaviGation/UserAdmin",
        name: "UserAdmin",
        component: () => import('../views/UserAdmin/UserAdmin.vue'),
        meta: {
          isShow: true,
          title: "用户管理"
        },
        children: [{
          path: "/NaviGation/UserAdmin/UserList",
          name: "UserList",
          component: () => import('../views/UserAdmin/comment/UserList.vue'),
          meta: {
            isShow: true,
            title: "用户管理下的用户列表"
          }
        }]
      },
      {
        path: "/NaviGation/JuAdmin",
        name: "JuAdmin",
        component: () => import('../views/JuAdmin/JuAdmin.vue'),
        meta: {
          isShow: true,
          title: "权限管理"
        },
        children: [{
            path: "/NaviGation/JuAdmin/RoleList",
            name: "RoleList",
            component: () => import('../views/JuAdmin/comment/RoleList.vue'),
            meta: {
              isShow: true,
              title: "权限管理下的角色列表"
            }
          },
          {
            path: "/NaviGation/JuAdmin/JuList",
            name: "JuList",
            component: () => import('../views/JuAdmin/comment/JuList.vue'),
            meta: {
              isShow: true,
              title: "权限管理下的权限列表"
            }
          }
        ]
      },
      {
        path: "/NaviGation/ComAdmin",
        name: "ComAdmin",
        component: () => import('../views/ComAdmin/ComAdmin.vue'),
        meta: {
          isShow: true,
          title: "商品管理"
        },
        children: [{
            path: "/NaviGation/ComAdmin/ComList",
            name: "ComList",
            component: () => import('../views/ComAdmin/comment/ComList.vue'),
            meta: {
              isShow: true,
              title: "商品管理下的商品列表"
            }
          },
          {
            path: "/NaviGation/ComAdmin/ParaMeter",
            name: "ParaMeter",
            component: () => import('../views/ComAdmin/comment/ParaMeter.vue'),
            meta: {
              isShow: true,
              title: "商品管理下的分类参数"
            }
          },
          {
            path: "/NaviGation/ComAdmin/ComClass",
            name: "ComClass",
            component: () => import('../views/ComAdmin/comment/ComClass.vue'),
            meta: {
              isShow: true,
              title: "商品管理下的商品分类"
            }
          },
          {
            path: "/NaviGation/ComAdmin/ComAdd",
            name: "ComAdd",
            component: () => import('../views/ComAdmin/comment/ComAdd.vue'),
            meta: {
              isShow: true,
              title: "商品管理下的商品添加"
            }
          }
        ]
      },
      {
        path: "/NaviGation/OrderAdmin",
        name: "OrderAdmin",
        component: () => import('../views/OrderAdmin/OrderAdmin.vue'),
        meta: {
          isShow: true,
          title: "订单管理"
        },
        children: [{
          path: "/NaviGation/OrderAdmin/OrderList",
          name: "OrderList",
          component: () => import('../views/OrderAdmin/comment/OrderList.vue'),
          meta: {
            isShow: true,
            title: "订单管理下的订单管理"
          }
        }]
      },
      {
        path: "/NaviGation/DataAdmin",
        name: "DataAdmin",
        component: () => import('../views/DataAdmin/DataAdmin.vue'),
        meta: {
          isShow: true,
          title: "数据统计"
        },
        children: [{
          path: "/NaviGation/DataAdmin/DataStats",
          name: "DataStats",
          component: () => import('../views/DataAdmin/comment/DataStats.vue'),
          meta: {
            isShow: true,
            title: "数据统计下的数据报表"
          }
        }]
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.matched.some(item => item.meta.isShow)) {
    if (!store.state.login.token) {
      next('/RegiSter')
    } else {
      next()
    }
  } else {
    next()
  }
})



export default router